/*
 * Copyright (C) 2011 Moritz Schmale <narrow.m@gmail.com>
 *
 * DropChest is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl.html>.
 */

package me.scotty86.DropChest;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Configuration {
	/* the config-file */
	private File file;
	private FlatFileReader reader;

	private int max_radius;
	private int default_radius;
	private long minecart_lock_wait;
	private double warning_fillstatus;
	private String warning_fillstatus_message;
	private boolean locketteCompatibility;
	private boolean teleportEnabled;

	List<String> mods;

	public Configuration(File file) {
		this.file = file;
		this.reader = new FlatFileReader(this.file, false);
		load();
	}

	private void load() {
		this.max_radius = this.reader.getInteger("max-radius", 16);
		this.default_radius = this.reader.getInteger("default-radius", 4);
		this.minecart_lock_wait = this.reader.getInteger("minecart-lock-wait",
				100);
		this.warning_fillstatus = this.reader.getInteger("warning-fillstatus",
				80);
		this.warning_fillstatus_message = this.reader.getString(
				"warning-fillstatus-message",
				"Your chest $name is nearly full($fill%)");
		this.locketteCompatibility = this.reader.getBoolean(
				"lockette-compatibility", false);
		this.teleportEnabled = this.reader.getBoolean("teleportEnabled", false);
		this.mods = new ArrayList<String>();

		String[] splt = this.reader.getString("mods", "").split(",");
		for (int i = 0; i < splt.length; i++)
			this.mods.add(splt[i]);
	}

	/**
	 * @return the letUsersProtectChests
	 */
	public boolean isLetUsersProtectChests() {
		// return letUsersProtectChests;
		return false;
	}

	public boolean isTeleportEnabled() {
		return this.teleportEnabled;
	}

	/**
	 * @return is the Player a mod?
	 */
	public boolean isMod(CommandSender player) {
		if (player == null)
			return false;
		if ((this.mods.contains(player.getName().toLowerCase()))
				|| (player.isOp()))
			return true;
		return false;
	}

	public boolean isMod(Player player) {
		if (player == null)
			return false;
		if ((this.mods.contains(player.getName().toLowerCase()))
				|| (player.isOp()))
			return true;
		return false;
	}

	/**
	 * @return the maxRadius
	 */
	public int getMaxRadius() {
		return this.max_radius;
	}

	/**
	 * @return the defaultRadius
	 */
	public int getDefaultRadius() {
		return this.default_radius;
	}

	/**
	 * @return the warnFillStatus
	 */
	public double getWarnFillStatus() {
		return this.warning_fillstatus;
	}

	/**
	 * @return the lock wait for minecarts
	 */
	public long getMinecartLockWait() {
		return this.minecart_lock_wait;
	}

	/**
	 * @return the warnFillStatus-Message
	 */
	public String getWarnString() {
		return this.warning_fillstatus_message;
	}

	/**
	 * @return is Lockette compatibility activated
	 */
	public boolean isLocketteCompatibilityActivated() {
		return this.locketteCompatibility;
	}

	/**
	 * @return is Protection enabled
	 */
	public boolean isProtectionEnabled() {
		return false;
	}

	/* obsolet */
	public int getIdleTimeAfterRedstone() {
		return 0;
	}
}